package com.dabai.simpleconnection_udp.utils;

import java.util.regex.Pattern;

/**
 * iputil
 *
 * @author Flower3
 * @date 2023/08/31
 */
public class IPUtils {
    /**
     * is ip
     *
     * @param str str
     * @return boolean
     */
    public static boolean isIP(String str) {
        String pattern = "^((\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(\\d{1,2}|1\\d{2}|2[0-4]\\d|25[0-5])$";
        return Pattern.matches(pattern, str);
    }

    /**
     * is端口
     *
     * @param str str
     * @return boolean
     */
    public static boolean isPort(String str) {
        try {
            int port = Integer.parseInt(str);
            return port >= 0 && port <= 65535;
        } catch (NumberFormatException e) {
            return false;
        }
    }
}